package cn.itcast.search.web;

import cn.itcast.hmall.dto.common.PageDTO;
import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.hmall.dto.search.SearchReqDTO;
import cn.itcast.hmall.pojo.item.ItemDoc;
import cn.itcast.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("search")
public class SearchController {

    @Autowired
    private SearchService searchService;


    @GetMapping("importItemData")
    public ResultDTO importItem(){
        return searchService.importItem();
    }

    @GetMapping("suggestion")
    public List<String> getSuggestions(@RequestParam("key") String prefix){
        return searchService.getSuggestions(prefix);
    }

    @PostMapping("filters")
    public Map<String, List<String>> getFilters(@RequestBody SearchReqDTO params){
        return searchService.getFilters(params);
    }

    @PostMapping("list")
    public PageDTO<ItemDoc> search(@RequestBody SearchReqDTO params) {
        return searchService.search(params);
    }
}
